import { message } from 'ant-design-vue'

import { userApi } from '@/apis'
import { useDialog } from '@/hooks'

type Params = {
  refresh: PromiseFunc
}

export function useFreeze({ refresh }: Params) {
  const { showConfirm } = useDialog()

  function handleFreeze(id: number) {
    showConfirm({
      content: '确认冻结账号？',
      onOk() {
        refresh(async () => {
          await userApi.frozeUser(id)
          message.success('冻结成功')
        })
      }
    })
  }

  function handleActive(id: number) {
    showConfirm({
      content: '确认启用账号？',
      onOk() {
        refresh(async () => {
          await userApi.activeUser(id)
          message.success('启用成功')
        })
      }
    })
  }

  return {
    handleActive,
    handleFreeze
  }
}
